package indi.zhifa.core.dataauth.sqlHelper.sqlNode;

public class VarSqlPhase implements SqlAnalysisNode {

    StringBuilder sb;
    boolean hasBrace;

    public VarSqlPhase(){
        sb = new StringBuilder();
        hasBrace = false;
    }

    @Override
    public String toSql() {
        return sb.toString();
    }

    @Override
    public SqlAnalysisNode addChar(char c) {

        if(c == '{'){
            hasBrace = true;
            return null;
        }
        if(hasBrace){
            if(c == '}'){
                return new NormalSqlPhase();
            }else{
                sb.append(c);
                return null;
            }
        }else{
            if(!Character.isUnicodeIdentifierPart(c)){
                return new NormalSqlPhase();
            }else{
                sb.append(c);
                return null;
            }
        }
    }
}
